package com.wk.springcloud.user.server.dao.impl;

import com.wk.springcloud.user.server.dao.UserDao;
import com.wk.springcloud.user.server.dao.impl.mapper.UserMapper;
import com.wk.springcloud.user.server.dao.impl.mapper.entity.User;
import com.wk.springcloud.util.tool.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class UserDaoImpl implements UserDao {

    @Autowired(required = false)
    private UserMapper userMapper;

    @Override
    public int save(User record) {
        record.setId(IdWorker.getId());
        return this.userMapper.insertSelective(record);
    }

    @Override
    public int deleteById(Long id) {
        return this.userMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateById(User record) {
        return this.userMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public User getById(Long id) {
        return this.userMapper.selectByPrimaryKey(id);
    }

}
